using System;
using BitMango.Diagnostics;
using UnityEngine;

[Serializable]
public struct Point
{
	public Point(int X, int Y)
	{
		this.x = X;
		this.y = Y;
	}

	public Point(int X, int Y, int Min, int Max)
	{
		this.x = X;
		this.y = Y;
		if (this.x > Max)
		{
			this.x = Max;
		}
		else if (this.x < Min)
		{
			this.x = Min;
		}
		if (this.y > Max)
		{
			this.y = Max;
		}
		else if (this.y < Min)
		{
			this.y = Min;
		}
	}

	public Point(Point P2)
	{
		this.x = 0;
		this.y = 0;
		if (P2 != null)
		{
			this.x = P2.x;
			this.y = P2.y;
		}
	}

	public int X
	{
		get
		{
			return this.x;
		}
		set
		{
			this.x = value;
		}
	}

	public int Y
	{
		get
		{
			return this.y;
		}
		set
		{
			this.y = value;
		}
	}

	public override string ToString()
	{
		return string.Format("[{0},{1}]", this.x, this.y);
	}

	public static bool operator ==(Point P1, Point P2)
	{
		return P1 != null && P2 != null && P1.x == P2.x && P1.y == P2.y;
	}

	public static bool operator !=(Point P1, Point P2)
	{
		return P1 != null && P2 != null && (P1.x != P2.x || P1.y != P2.y);
	}

	public static Point operator -(Point P1, Point P2)
	{
		return new Point(P1.X - P2.X, P1.Y - P2.Y);
	}

	public override bool Equals(object P2)
	{
		Debugger.Assert(P2 != null);
		if (P2 == null)
		{
			return false;
		}
		Point point = (Point)P2;
		return point != null && this.x == point.x && this.y == point.y;
	}

	public override int GetHashCode()
	{
		return this.x ^ this.y;
	}

	public void Set(Point P2)
	{
		if (P2 != null)
		{
			this.x = P2.x;
			this.y = P2.y;
		}
	}

	public void Set(int X, int Y)
	{
		this.x = X;
		this.y = Y;
	}

	public float DistanceTo(Point P2)
	{
		if (P2 == null)
		{
			return -1f;
		}
		return Mathf.Sqrt((float)((this.x - P2.x) * (this.x - P2.x) + (this.y - P2.y) * (this.y - P2.y)));
	}

	public void SetFromOffset(Point P1, Point P2)
	{
		this.x = 0;
		this.y = 0;
		if (P1 == null)
		{
			return;
		}
		if (P2 == null)
		{
			return;
		}
		this.x = P1.x - P2.x;
		this.y = P1.y - P2.y;
	}

	public void SetFromOffset(Point P1, Point P2, int Min, int Max)
	{
		this.x = 0;
		this.y = 0;
		if (P1 == null)
		{
			return;
		}
		if (P2 == null)
		{
			return;
		}
		this.x = P1.x - P2.x;
		this.y = P1.y - P2.y;
		if (this.x > Max)
		{
			this.x = Max;
		}
		else if (this.x < Min)
		{
			this.x = Min;
		}
		if (this.y > Max)
		{
			this.y = Max;
		}
		else if (this.y < Min)
		{
			this.y = Min;
		}
	}

	public Point.CardinalDirection DirectionTo(Point P2)
	{
		if (P2 == null)
		{
			return Point.CardinalDirection.None;
		}
		Point[] array = new Point[]
		{
			new Point(0, -1),
			new Point(1, -1),
			new Point(1, 0),
			new Point(1, 1),
			new Point(0, 1),
			new Point(-1, 1),
			new Point(-1, 0),
			new Point(-1, -1)
		};
		Point p = default(Point);
		p.SetFromOffset(this, P2, -1, 1);
		int num = 0;
		foreach (Point p2 in array)
		{
			if (p2 == p)
			{
				return (Point.CardinalDirection)num;
			}
			num++;
		}
		return Point.CardinalDirection.None;
	}

	public bool Adjacent(Point P2)
	{
		return this.DistanceTo(P2) == 1f;
	}

	public static Point Empty = new Point(0, 0);

	public int x;

	public int y;

	public enum CardinalDirection
	{
		None = -1,
		N,
		NE,
		E,
		SE,
		S,
		SW,
		W,
		NW
	}
}
